package com.ug_project.adapters

import android.app.Activity
import android.content.Context
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ug_project.objects.isNull
import com.ug_project.views.click

/**
 * Created by yeganaaa on 3/7/2017.
 */

//class RecyclerExpandableAdapter<T : MultiItemEntity>(val context: Context, var datas: List<T>) :
//        BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder>(datas) {
//    init {
////        openLoadAnimation()
//    }
//
//    private var _OnViewRecycled: ((View) -> Unit) = {}
//    private var _inflater: LayoutInflater? = null
//
//    open fun addHeader(layoutRedId: Int, action: (view: View) -> View) {
//        _inflater.isNull {
//            _inflater = LayoutInflater.from(context)
//        }
//        val headerView = _inflater?.inflate(layoutRedId, null, false)
//        addHeaderView(action(headerView!!))
//    }
//
//    open fun addFooter(layoutRedId: Int, action: (view: View) -> View) {
//        _inflater.isNull {
//            _inflater = LayoutInflater.from(context)
//        }
//        val footerView = _inflater?.inflate(layoutRedId, null, false)
//
//        addFooterView(action(footerView!!))
//    }
//
//
//    open fun addLevel(level: Int, layoutId: Int) {
//        addItemType(level, layoutId)
//    }
//
//    private var _OnBindData: ((level: Int, view: View, data: MultiItemEntity, position: Int) -> Unit)? = null
//    private var _OnItemClick: (level: Int, data: MultiItemEntity, position: Int) -> Unit = { a, b, c -> }
//
//    open fun onBindData(action: (level: Int, view: View, data: MultiItemEntity, position: Int) -> Unit) {
//        _OnBindData = action
//    }
//
//    open fun onLevelItemClick(action: (level: Int, data: MultiItemEntity, position: Int) -> Unit) {
//        _OnItemClick = action
//    }
//
//    override fun convert(helper: BaseViewHolder, item: MultiItemEntity?) {
//
//        var data = datas[helper.adapterPosition]
//        if (data is AbstractExpandableItem<*>) {
//            helper.itemView.click {
//                if ((data as AbstractExpandableItem<*>).isExpanded) {
//                    collapse(helper.adapterPosition)
//                } else {
//                    expand(helper.adapterPosition)
//                }
//                _OnItemClick(helper.itemViewType, data, helper.adapterPosition)
//            }
//        }
//
//        _OnBindData?.invoke(helper.itemViewType, helper.itemView, datas[helper.adapterPosition], helper.adapterPosition)
//    }
//
//
//    override fun onViewRecycled(holder: BaseViewHolder) {
//        super.onViewRecycled(holder)
//        _OnViewRecycled.invoke(holder.itemView)
//    }
//
//    open fun onViewRecycled(action: (View) -> Unit) {
//        _OnViewRecycled = action
//    }
//
//    fun refresh() {
//        notifyDataSetChanged()
//    }
//
//}
//
//
//fun <T : MultiItemEntity> Fragment.createRecyclerExpandableAdapter(datas: List<T>,
//                                                          creator: RecyclerExpandableAdapter<T>.() -> Unit): RecyclerExpandableAdapter<T> {
//    val adapter = RecyclerExpandableAdapter(context, datas)
//    adapter.creator()
//    return adapter
//}
//fun <T : MultiItemEntity> Activity.createRecyclerExpandableAdapter(datas: List<T>,
//                                                                   creator: RecyclerExpandableAdapter<T>.() -> Unit): RecyclerExpandableAdapter<T> {
//    val adapter = RecyclerExpandableAdapter(this, datas)
//    adapter.creator()
//    return adapter
//}